package com.ruoyi.web.controller.dangerControl;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.HdCheckPlan;
import com.ruoyi.dangerControl.service.IHdCheckPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患-检查计划Controller
 *
 * @author lth
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/dangerControl/plan")
public class HdCheckPlanController extends BaseController
{
    @Autowired
    private IHdCheckPlanService hdCheckPlanService;

    /**
     * 查询隐患-检查计划列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdCheckPlan hdCheckPlan)
    {
        startPage();
        List<HdCheckPlan> list = hdCheckPlanService.selectHdCheckPlanList(hdCheckPlan);
        return getDataTable(list);
    }

    /**
     * 导出隐患-检查计划列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:export')")
    @Log(title = "隐患-检查计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdCheckPlan hdCheckPlan)
    {
        List<HdCheckPlan> list = hdCheckPlanService.selectHdCheckPlanList(hdCheckPlan);
        ExcelUtil<HdCheckPlan> util = new ExcelUtil<HdCheckPlan>(HdCheckPlan.class);
        util.exportExcel(response, list, "隐患-检查计划数据");
    }

    /**
     * 获取隐患-检查计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hdCheckPlanService.selectHdCheckPlanById(id));
    }

    /**
     * 新增隐患-检查计划
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:add')")
    @Log(title = "隐患-检查计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdCheckPlan hdCheckPlan)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        hdCheckPlan.setId(id);
        hdCheckPlan.setCreateAt(new Date());
        return toAjax(hdCheckPlanService.insertHdCheckPlan(hdCheckPlan));
    }

    /**
     * 修改隐患-检查计划
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:edit')")
    @Log(title = "隐患-检查计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdCheckPlan hdCheckPlan)
    {
        return toAjax(hdCheckPlanService.updateHdCheckPlan(hdCheckPlan));
    }

    /**
     * 删除隐患-检查计划
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:remove')")
    @Log(title = "隐患-检查计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hdCheckPlanService.deleteHdCheckPlanByIds(ids));
    }

}
